package utils;

import java.io.File;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Point;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.Toast;
import app.fitness.fragment.DashBoardFragment;

import com.razerzone.android.fitness.R;

public class Utils {

	private static AlertDialog mAdConnection = null;
	private Context context;
	private static Handler mHandler = new Handler();
	private ProgressDialog mPdWaiting = null;

	public Utils(Context context) {
		setContext(context);
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	/**
	 * Check fill blank
	 */
	public static boolean checkFillBlank(EditText et) {
		if (et.getText().toString().equals("")) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Check fill password characters At least 8 characters
	 */
	public static boolean checkFillPassword(EditText et) {
		if (et.getText().toString().length() >= 8) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Check language in System Settings
	 */
	public static int checkLanguageInSettings() {
		if (Locale.getDefault().getLanguage().equals("en")) {
			/**
			 * English
			 */
			return 0;
		} else if (Locale.getDefault().getLanguage().equals("zh")) {
			/**
			 * Simplifier Chinese
			 */
			return 1;
		}
		return 0;
	}

	/**
	 * Clear Application Data
	 */
	public static void clearApplicationData(Context context) {
		File cache = context.getCacheDir();
		File appDir = new File(cache.getParent());
		if (appDir.exists()) {
			String[] children = appDir.list();
			for (String s : children) {
				if (!s.equals("lib")) {
					deleteDir(new File(appDir, s));
				}
			}
		}
	}

	/**
	 * Clear Application Cache
	 */
	public static boolean deleteDir(File dir) {
		if (dir != null && dir.isDirectory()) {
			String[] children = dir.list();
			for (int i = 0; i < children.length; i++) {
				boolean success = deleteDir(new File(dir, children[i]));
				if (!success) {
					return false;
				}
			}
		}

		return dir.delete();
	}

	/**
	 * Check text is number or not
	 */
	public static boolean checkIntegerValue(EditText et) {
		try {
			Integer.parseInt(et.getText().toString());

			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	}

	/**
	 * Get correct date again after changed to expected language
	 */
	public static String getCorrectDate(Context context, Calendar mCal) {
		String TODAY = null;
		switch (mCal.get(Calendar.MONTH)) {
		case Calendar.JANUARY:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.jannuary_);
			break;
		case Calendar.FEBRUARY:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.february_);
			break;
		case Calendar.MARCH:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.march_);
			break;
		case Calendar.APRIL:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.april_);
			break;
		case Calendar.MAY:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.may_);
			break;
		case Calendar.JUNE:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.june_);
			break;
		case Calendar.JULY:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.july_);
			break;
		case Calendar.AUGUST:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.august_);
			break;
		case Calendar.SEPTEMBER:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.september_);
			break;
		case Calendar.OCTOBER:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.october_);
			break;
		case Calendar.NOVEMBER:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.november_);
			break;
		case Calendar.DECEMBER:
			TODAY = mCal.get(Calendar.DAY_OF_MONTH) + " "
					+ context.getString(R.string.december_);
			break;
		}

		return TODAY;
	}

	/**
	 * Get correct time
	 */
	public static int[] getCorrectHours(int hours, int minutes) {
		int[] time = new int[2];

		time[0] = Integer.valueOf(hours);
		time[1] = Integer.valueOf(minutes);
		while (time[1] >= 60) {
			time[1] -= 60;
			time[0]++;
		}

		return time;
	}

	/**
	 * Get correct date again after changed to expected language
	 */
	public static String getCorrectMonth(Context context, Calendar mCal,
			int current_month) {
		String TODAY = null;
		int month = 0;

		/**
		 * Check should use month index from Calendar or exact index of current
		 * month
		 */
		if (mCal != null) {
			month = mCal.get(Calendar.MONTH);
		} else {
			month = current_month;
		}

		switch (month) {
		case Calendar.JANUARY:
			TODAY = context.getString(R.string.jannuary_);
			break;
		case Calendar.FEBRUARY:
			TODAY = context.getString(R.string.february_);
			break;
		case Calendar.MARCH:
			TODAY = context.getString(R.string.march_);
			break;
		case Calendar.APRIL:
			TODAY = context.getString(R.string.april_);
			break;
		case Calendar.MAY:
			TODAY = context.getString(R.string.may_);
			break;
		case Calendar.JUNE:
			TODAY = context.getString(R.string.june_);
			break;
		case Calendar.JULY:
			TODAY = context.getString(R.string.july_);
			break;
		case Calendar.AUGUST:
			TODAY = context.getString(R.string.august_);
			break;
		case Calendar.SEPTEMBER:
			TODAY = context.getString(R.string.september_);
			break;
		case Calendar.OCTOBER:
			TODAY = context.getString(R.string.october_);
			break;
		case Calendar.NOVEMBER:
			TODAY = context.getString(R.string.november_);
			break;
		case Calendar.DECEMBER:
			TODAY = context.getString(R.string.december_);
			break;
		}
		return TODAY;
	}

	/**
	 * Get correct index of month again after changed to expected language
	 */
	public static int getCorrectIndexMonth(Context context, String date) {
		int month = 0;
		if (date.equals(context.getString(R.string.jannuary_))) {
			month = Calendar.JANUARY;
		} else if (date.equals(context.getString(R.string.february_))) {
			month = Calendar.FEBRUARY;
		} else if (date.equals(context.getString(R.string.march_))) {
			month = Calendar.MARCH;
		} else if (date.equals(context.getString(R.string.april_))) {
			month = Calendar.APRIL;
		} else if (date.equals(context.getString(R.string.may_))) {
			month = Calendar.MAY;
		} else if (date.equals(context.getString(R.string.june_))) {
			month = Calendar.JUNE;
		} else if (date.equals(context.getString(R.string.july_))) {
			month = Calendar.JULY;
		} else if (date.equals(context.getString(R.string.august_))) {
			month = Calendar.AUGUST;
		} else if (date.equals(context.getString(R.string.september_))) {
			month = Calendar.SEPTEMBER;
		} else if (date.equals(context.getString(R.string.october_))) {
			month = Calendar.OCTOBER;
		} else if (date.equals(context.getString(R.string.november_))) {
			month = Calendar.NOVEMBER;
		} else if (date.equals(context.getString(R.string.december_))) {
			month = Calendar.DECEMBER;
		}

		return month;
	}

	/**
	 * Get current day
	 * 
	 * @return
	 */
	public static String getCurrentDate(Context context) {
		Calendar mCalendarBegin = Calendar.getInstance();
		mCalendarBegin.add(Calendar.DAY_OF_MONTH, 0);

		/**
		 * Add Date of 12 AM
		 */
		mCalendarBegin.set(Calendar.HOUR_OF_DAY, 0);
		mCalendarBegin.set(Calendar.MINUTE, 0);
		mCalendarBegin.set(Calendar.SECOND, 0);

		Date mDateBegin = mCalendarBegin.getTime();
		DashBoardFragment.singleTon.setCurrentDateBegin(mDateBegin);

		String TODAY = getCorrectDate(context, mCalendarBegin);

		/**
		 * Add Date of 12 PM
		 */
		mCalendarBegin.add(Calendar.DAY_OF_MONTH, 1);
		mCalendarBegin.set(Calendar.HOUR_OF_DAY, 0);
		mCalendarBegin.set(Calendar.MINUTE, 0);
		mCalendarBegin.set(Calendar.SECOND, 0);

		DashBoardFragment.singleTon.setCurrentDateEnd(mCalendarBegin.getTime());

		return TODAY;
	}

	/**
	 * Get current month
	 * 
	 * @return
	 */
	public static Calendar getCurrentMonth() {
		Calendar mCalendar = Calendar.getInstance();
		mCalendar.add(Calendar.MONTH, 0);

		return mCalendar;
		// return sdf.format(cal.getTime());
	}

	/**
	 * Get current week
	 * 
	 * @return
	 */
	public static String getCurrentWeek(Context context, Calendar mCalendar) {
		Date date = new Date();
		mCalendar.setTime(date);

		// 1 = Sunday, 2 = Monday, etc.
		int day_of_week = mCalendar.get(Calendar.DAY_OF_WEEK);

		int monday_offset;
		if (day_of_week == 1) {
			monday_offset = -6;
		} else
			monday_offset = (2 - day_of_week); // need to minus back
		mCalendar.add(Calendar.DAY_OF_YEAR, monday_offset);

		Date mDateMonday = mCalendar.getTime();

		// Save Monday Date into singleton
		DashBoardFragment.singleTon.setDateMonday(mDateMonday);

		// return 6 the next days of current day (object cal save current day)
		mCalendar.add(Calendar.DAY_OF_YEAR, 6);
		Date mDateSunday = mCalendar.getTime();

		// Save Sunday date into singleton
		DashBoardFragment.singleTon.setDateSunday(mDateSunday);

		// Monday
		Calendar mCalendarMonday = Calendar.getInstance();
		mCalendarMonday.setTime(mDateMonday);

		// Sunday
		Calendar mCalendarSunday = Calendar.getInstance();
		mCalendarSunday.setTime(mDateSunday);

		int MONDAY = mCalendarMonday.get(Calendar.DAY_OF_MONTH);
		int SUNDAY = mCalendarSunday.get(Calendar.DAY_OF_MONTH);

		// Sub String
		if (mCalendarMonday.get(Calendar.MONTH) == mCalendarSunday
				.get(Calendar.MONTH)) {
			return (MONDAY + " - " + SUNDAY + " "
			// + Month.month_text[mCalendarSunday
			// .get(Calendar.MONTH)]).toUpperCase();
			+ Utils.getCorrectMonth(context, mCalendarSunday, -1))
					.toUpperCase();
		} else {
			return (MONDAY
					+ " "
					// + Month.month_text[mCalendarMonday.get(Calendar.MONTH)]
					// + " - " + SUNDAY + " " + Month.month_text[mCalendarSunday
					// .get(Calendar.MONTH)]).toUpperCase();
					+ Utils.getCorrectMonth(context, mCalendarMonday, -1)
					+ " - " + SUNDAY + " " + Utils.getCorrectMonth(context,
					mCalendarSunday, -1)).toUpperCase();
		}
	}

	/**
	 * Get current year
	 * 
	 * @return
	 */
	public static String getCurrentYear() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.YEAR, 0);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		return sdf.format(cal.getTime());
	}

	/**
	 * Get Float format with 4 digits
	 */
	public static String getFloatFormat(float value) {
		return String.format("%.3f", value);
	}

	/**
	 * Get yesterday
	 * 
	 * @return
	 */
	public static String getLastDate(Context context, int i) {
		Calendar mCalendarBegin = Calendar.getInstance();
		mCalendarBegin.add(Calendar.DAY_OF_YEAR, -i);

		/**
		 * Add Date of 12 AM
		 */
		mCalendarBegin.set(Calendar.HOUR_OF_DAY, 0);
		mCalendarBegin.set(Calendar.MINUTE, 0);
		mCalendarBegin.set(Calendar.SECOND, 0);

		Date mDateBegin = mCalendarBegin.getTime();
		DashBoardFragment.singleTon.setCurrentDateBegin(mDateBegin);

		String TODAY = getCorrectDate(context, mCalendarBegin) + " "
				+ mCalendarBegin.get(Calendar.YEAR);

		/**
		 * Add Date of 11 PM
		 */
		mCalendarBegin.add(Calendar.DAY_OF_MONTH, 1);
		mCalendarBegin.set(Calendar.HOUR_OF_DAY, 0);
		mCalendarBegin.set(Calendar.MINUTE, 0);
		mCalendarBegin.set(Calendar.SECOND, 0);

		Date mDateEnd = mCalendarBegin.getTime();
		DashBoardFragment.singleTon.setCurrentDateEnd(mDateEnd);

		return TODAY;
	}

	/**
	 * Get previous month
	 * 
	 * @return
	 */
	public static Calendar getLast1Month(int i) {
		Calendar mCalendar = Calendar.getInstance();
		mCalendar.add(Calendar.MONTH, -i);

		return mCalendar;
	}

	/**
	 * Get previous 3 months ago
	 * 
	 * @return
	 */
	public static Calendar getLast3MonthsFirst(Context context, int i) {
		Calendar mCalendar = Calendar.getInstance();
		mCalendar.add(Calendar.MONTH, -3 * i + 1);

		return mCalendar;
	}
	
	/**
	 * Get next 3 months
	 * 
	 * @return
	 */
	public static Calendar getLast3MonthsLast(Context context, int i) {
		Calendar mCalendar = Calendar.getInstance();
		mCalendar.add(Calendar.MONTH, -3 * i);

		return mCalendar;
	}

	/**
	 * Get last week
	 * 
	 * @return
	 */
	public static String getLastWeek(Context context, Calendar mCalendar,
			int monday, int sunday) {
		/**
		 * Need find correct Monday by pass correct Index of Monday before get
		 * correct Sunday by plus 6 days
		 */
		// Monday
		mCalendar.add(Calendar.DAY_OF_YEAR, monday);
		Date mDateMonday = mCalendar.getTime();

		// Save into singleton
		DashBoardFragment.singleTon.setDateMonday(mDateMonday);

		// Sunday
		mCalendar.add(Calendar.DAY_OF_YEAR, sunday);
		Date mDateSunday = mCalendar.getTime();

		// Save into singleton
		DashBoardFragment.singleTon.setDateSunday(mDateSunday);

		// Monday
		Calendar mCalendarMonday = Calendar.getInstance();
		mCalendarMonday.setTime(mDateMonday);

		// Sunday
		Calendar mCalendarSunday = Calendar.getInstance();
		mCalendarSunday.setTime(mDateSunday);

		int MONDAY = mCalendarMonday.get(Calendar.DAY_OF_MONTH);
		int SUNDAY = mCalendarSunday.get(Calendar.DAY_OF_MONTH);

		// Sub String
		if (mCalendarMonday.get(Calendar.MONTH) == mCalendarSunday
				.get(Calendar.MONTH)) {
			return (MONDAY + " - " + SUNDAY + " "
			// + Month.month_text[mCalendarSunday
			// .get(Calendar.MONTH)]).toUpperCase();
			+ Utils.getCorrectMonth(context, mCalendarSunday, -1))
					.toUpperCase();
		} else {
			return (MONDAY
					+ " "
					// + Month.month_text[mCalendarMonday.get(Calendar.MONTH)]
					// + " - " + SUNDAY + " " + Month.month_text[mCalendarSunday
					// .get(Calendar.MONTH)]).toUpperCase();
					+ Utils.getCorrectMonth(context, mCalendarMonday, -1)
					+ " - " + SUNDAY + " " + Utils.getCorrectMonth(context,
					mCalendarSunday, -1)).toUpperCase();
		}
	}

	/**
	 * Get previous year ago
	 * 
	 * @return
	 */
	public static String getLastYear(int i) {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.YEAR, -i);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		return sdf.format(cal.getTime());
	}

	/**
	 * Get Next week
	 * 
	 * @param mCalendar
	 * @return
	 */
	public static String getNextWeek(Context context, Calendar mCalendar,
			int monday, int sunday) {
		/**
		 * Need find correct Monday by pass correct Index of Monday before get
		 * correct Sunday by plus 6 days
		 */
		// Monday
		mCalendar.add(Calendar.DAY_OF_YEAR, monday);
		Date mDateMonday = mCalendar.getTime();

		// Save into singleton
		DashBoardFragment.singleTon.setDateMonday(mDateMonday);

		// Sunday
		mCalendar.add(Calendar.DAY_OF_YEAR, sunday);
		Date mDateSunday = mCalendar.getTime();

		// Save into singleton
		DashBoardFragment.singleTon.setDateSunday(mDateSunday);

		// Monday
		Calendar mCalendarMonday = Calendar.getInstance();
		mCalendarMonday.setTime(mDateMonday);

		// Sunday
		Calendar mCalendarSunday = Calendar.getInstance();
		mCalendarSunday.setTime(mDateSunday);

		int MONDAY = mCalendarMonday.get(Calendar.DAY_OF_MONTH);
		int SUNDAY = mCalendarSunday.get(Calendar.DAY_OF_MONTH);

		// Sub String
		if (mCalendarMonday.get(Calendar.MONTH) == mCalendarSunday
				.get(Calendar.MONTH)) {
			return (MONDAY + " - " + SUNDAY + " "
			// + Month.month_text[mCalendarSunday
			// .get(Calendar.MONTH)]).toUpperCase();
			+ Utils.getCorrectMonth(context, mCalendarSunday, -1))
					.toUpperCase();
		} else {
			return (MONDAY
					+ " "
					// + Month.month_text[mCalendarMonday.get(Calendar.MONTH)]
					// + " - " + SUNDAY + " " + Month.month_text[mCalendarSunday
					// .get(Calendar.MONTH)]).toUpperCase();
					+ Utils.getCorrectMonth(context, mCalendarMonday, -1)
					+ " - " + SUNDAY + " " + Utils.getCorrectMonth(context,
					mCalendarSunday, -1)).toUpperCase();
		}
	}

	/**
	 * Get Screen Width
	 */
	public static int getWidth(Context context) {
		Display display = ((Activity) context).getWindowManager()
				.getDefaultDisplay();
		Point size = new Point();
		display.getSize(size);
		return size.x;
	}

	/**
	 * get Number (float or int) from String
	 */
	public static String getNumberOfString(String str) {
		str = str.replaceAll("[^\\d.]", "");
		return str;
	}

	/**
	 * Hide alert connection dialog
	 */
	public static void hideConnectionDialog() {
		mHandler.post(new Runnable() {

			@Override
			public void run() {
				mAdConnection.dismiss();
			}
		});
	}

	/**
	 * Hide pop up window
	 */
	public static void hidePopUp(PopupWindow mPw) {
		if (mPw != null && mPw.isShowing()) {
			mPw.dismiss();
		}
	}

	/**
	 * Hide progress dialog
	 */
	public void hideProgressDialog() {
		if (mPdWaiting != null && mPdWaiting.isShowing()) {
			mPdWaiting.dismiss();
			mPdWaiting = null;
		}
	}

	/**
	 * Hidden keyboard
	 */
	public static void hideSoftKeyboard(Context context) {
		try {
			InputMethodManager mImm = (InputMethodManager) context
					.getSystemService(Context.INPUT_METHOD_SERVICE);
			mImm.hideSoftInputFromWindow(((Activity) context).getCurrentFocus()
					.getWindowToken(), 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void hideSoftKeyboard(Activity activity) {
		activity.getWindow().setSoftInputMode(InputMethodManager.RESULT_HIDDEN);
	}

	public void hideSoftKeyboard(EditText et) {
		InputMethodManager imm = (InputMethodManager) context
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
		imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
	}

	/**
	 * Initialize alert connection dialog
	 */
	// public static void initialConnectionDialog(final Context context) {
	// mHandler.post(new Runnable() {
	//
	// @Override
	// public void run() {
	// mAdConnection = new AlertDialog.Builder(context).create();
	// mAdConnection.setTitle(context
	// .getString(R.string.title_failed_connection));
	// mAdConnection.setIcon(R.drawable.ibtn_error_dismiss);
	// mAdConnection.setCancelable(false);
	// mAdConnection.setMessage(context
	// .getString(R.string.content_failed_server_connection));
	// mAdConnection.setButton(DialogInterface.BUTTON_POSITIVE,
	// context.getString(R.string.try_again),
	// new DialogInterface.OnClickListener() {
	// @Override
	// public void onClick(DialogInterface dialog9,
	// int whichButton) {
	// hideConnectionDialog();
	//
	// // New intent to wireless setting
	// context.startActivity(new Intent(
	// android.provider.Settings.ACTION_WIRELESS_SETTINGS));
	// }
	// });
	// mAdConnection.setButton(DialogInterface.BUTTON_NEGATIVE,
	// context.getString(R.string.quit),
	// new DialogInterface.OnClickListener() {
	// @Override
	// public void onClick(DialogInterface dialog9,
	// int whichButton) {
	// android.os.Process
	// .killProcess(android.os.Process.myPid());
	// }
	// });
	// }
	// });
	// }

	/**
	 * Is App already installed or not
	 */
	public boolean isAppInstalled(String packageName) {
		if (context != null) {
			PackageManager pm = context.getPackageManager();
			boolean installed = false;
			try {
				pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
				installed = true;
			} catch (PackageManager.NameNotFoundException e) {
				installed = false;
			}

			return installed;
		}

		return false;
	}

	/**
	 * Check network connection
	 */
	public boolean isNetworkOnline() {
		boolean status = false;
		try {
			ConnectivityManager cm = (ConnectivityManager) context
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo netInfo = cm.getNetworkInfo(0);
			if (netInfo != null
					&& netInfo.getState() == NetworkInfo.State.CONNECTED) {
				status = true;
			} else {
				netInfo = cm.getNetworkInfo(1);
				if (netInfo != null
						&& netInfo.getState() == NetworkInfo.State.CONNECTED)
					status = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return status;
	}

	/**
	 * Remove view parent
	 */
	public static void removeViewParent(View v) {
		((ViewGroup) v.getParent()).removeView(v);
	}

	/**
	 * Set only default language
	 * 
	 * @param context
	 * @param lang
	 */
	public static void setDefaultLanguage(Context context, String lang) {
		Locale locale = new Locale(lang);
		Locale.setDefault(locale);
		Configuration config = new Configuration();
		config.locale = locale;
		context.getResources().updateConfiguration(config,
				context.getResources().getDisplayMetrics());
	}

	/**
	 * Show action sheet dialog
	 * 
	 * @param resource
	 */
	public static PopupWindow showActionSheetDialog(Context context, View v) {
		// Get display of the screen
		Display display = ((Activity) context).getWindowManager()
				.getDefaultDisplay();
		Point p = new Point();
		display.getSize(p);

		// Creating the PopupWindow
		final PopupWindow mPw = new PopupWindow(context);
		mPw.setContentView(v);
		mPw.setWidth(LayoutParams.MATCH_PARENT);
		mPw.setHeight(LayoutParams.WRAP_CONTENT);

		// Displaying the pop up at the specified location.
		mPw.showAtLocation(v, Gravity.BOTTOM, 0, 0);

		return mPw;
	}

	/**
	 * Show Date Format
	 */
	public static String showDate(Date date) {
		String time = null;

		Calendar mCalendar = Calendar.getInstance();
		mCalendar.setTime(date);

		time = mCalendar.get(Calendar.HOUR_OF_DAY)
				+ "h "
				+ mCalendar.get(Calendar.MINUTE)
				+ "m "
				+ mCalendar.get(Calendar.DAY_OF_MONTH)
				+ " "
				+ mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT,
						Locale.US) + " " + mCalendar.get(Calendar.YEAR);

		return time;
	}

	/**
	 * Show integer format
	 */
	public static String showIntergerFormat(String str) {
		Double db = Double.parseDouble(str);
		DecimalFormat mDecimalFormat = new DecimalFormat("###,###.###");
		str = mDecimalFormat.format(db);
		return str;
	}

	/**
	 * Show progress dialog
	 */
	public void showProgressDialog() {
		if (mPdWaiting == null) {
			mPdWaiting = ProgressDialog.show(context,
					context.getString(R.string.title_loading),
					context.getString(R.string.content_loading));
		}
	}

	/**
	 * Show progress dialog
	 */
	public void showToast(String text) {
		Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
	}
}
